package yawning.mew.cat;

import yawning.mew.cat.CatModelSimulation.SimulatorProperty;
import yawning.mew.sim.SimulationAction;
import yawning.mew.sim.SimulationEventAction;

public class EventRunAway extends SimulationEventAction {
	CatModelSimState mState;
	boolean mIsDone;
	double mRunTime;

	protected EventRunAway(CatModelSimState state) {
		super(state.mSimEngine);
		mState = state;
		mRunTime = mState.mSimEngine.getConfig().getDouble(SimulatorProperty.FERALCHARGETRAVELTIME);
	}

	@Override
	public double perform() {
		if (mState.mActiveTarget == null) return SimulationAction.ACTION_FAIL;
		if (mState.isInMeleeRange() == false) return SimulationAction.ACTION_FAIL;

		if (mState.mIsLogging) mState.mLog.log("Gaining distance for Feral Charge\n");

		// Stop the swing timer and note that we are away from target.
		mState.mMeleeSwingEv.stop();
		mState.mIsInMeleeRange = false;

		schedule(mRunTime);

		return 0;
	}
}
